package 滑动;

import java.util.Arrays;

public class _2090半径为k的子数组平均值 {

    public static int[] getAverages(int[] nums, int k) {
        long sum=0;
        int n =nums.length;
        int[] res =new int[n];
        Arrays.fill(res, -1);
        for (int i = 0; i < nums.length; i++) {
            sum+=nums[i];
            if(i<2*k){
                continue;
            }

            res[i-k]=(int)(sum/(2*k+1));
            sum-=nums[i-2*k];

        }
        return res;
    }

    public static void main(String[] args) {
        //n=9,k=3 窗口固定是7=2k+1
        //有效3,4,5
        //0,1,2     n-3,n-2,n-1
        int[] r1 = getAverages(new int[]{7,4,3,9,1,8,5,2,6}, 3);
        System.out.println(Arrays.toString(r1));

    }
}
